#include <pic18fregs.h>
#include "usart.h"


void usart_init() {
	TRISCbits.TRISC7=1; //Make UART RX pin input
	TRISCbits.TRISC6=0; //Make UART TX pin output

        SPBRG=51;     //9600@16MHz Osc

	TXSTAbits.BRGH=1;
	TXSTAbits.SYNC=0;
	RCSTAbits.SPEN=1;
	RCSTAbits.CREN=1;

	TXSTAbits.TXEN=0;
	TXSTAbits.TXEN=1;
	PIE1bits.RCIE=0;
	PIE1bits.TXIE=0;
	PIR1bits.RCIF=0;

}

unsigned char usart_recv() {
	while(!PIR1bits.RCIF);
	return RCREG;
}

void usart_send(unsigned char c) {
	while(!PIR1bits.TXIF);
	TXREG=c;
}

